import { observable, action , runInAction } from 'mobx';
import { Http } from '../services/Http';
import { getAllCompanys } from '../basicData/api'

namespace common {
  export const http: Http = new Http(); 
}

export class LoginStore {
  @observable public isRegister: boolean;
  @observable public allCompany: Array<{}>;

  public constructor() {
    this.isRegister = false
  }

  @action public register = (bool:boolean) => {
    this.isRegister = bool;
  }

  // 获取全部公司
  @action getAllCompany = () => {
    getAllCompanys().then((res: any) => {
      const arr: Array<{}> = [];
      
      res.result.map((item: any) => {
        const obj = {
          id: item.id,
          code: item.companyCode,
          name: item.companyName
        }
        arr.push(obj)
      })
      runInAction( () => {
        this.allCompany = arr
      })
    })
  }
}